import axios from 'axios';
axios.interceptors.request.use(config => {
    //这边加载loading
    return config
}, error => { return Promise.reject(error) });

axios.interceptors.response.use(response => {
    //这边关闭loading
    return response
}, error => { return Promise.reject(error) });
const AJAX_SRC = 'http://ddfwechat.eastall.com/';
const utils = {
    AJAX_SRC: AJAX_SRC,

    ajax(url , params , method = 'post'){
        return new Promise(function(resolve, reject) {
            //跨域处理
            let params1 = new URLSearchParams();
            for(let i in params){ params1.append(i , params[i]);}
            //跨域处理
            axios({
                url: url,
                method: method,
                data:params1
            }).then(function(res){
                resolve(res.data)
            }).catch(function(err){
                reject(err)
            });
        })
    },
    getLocalStorage(name){
        let obj = window.localStorage.getItem(name);
        return obj;
    },
    setLocalStorage(name, value) {
        value = typeof value != 'object' ? value : JSON.stringify(value);
        window.localStorage.setItem(name, value);
    }

};
export default utils;
